﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MusicOnLine.Models;

namespace MusicOnLine.Common
{
    public class AlbumUploadBinder:IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (!string.IsNullOrEmpty(bindingContext.ModelName) && !bindingContext.ValueProvider.ContainsPrefix(bindingContext.ModelName))
            {
                if (!bindingContext.FallbackToEmptyPrefix)
                    return null;
                bindingContext = new ModelBindingContext { 
                    ModelState=bindingContext.ModelState,
                    ModelMetadata=bindingContext.ModelMetadata,
                    PropertyFilter=bindingContext.PropertyFilter,
                    ValueProvider=bindingContext.ValueProvider
                };
            }
            bindingContext.ModelMetadata.Model = new AlbumUploadModel();
            var valueProvider = bindingContext.ValueProvider;
            
            string key = bindingContext.ModelName;
            ValueProviderResult vpr = bindingContext.ValueProvider.GetValue(key);
            
            return null;
        }
    }
}